using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;

public class ArchiveMgr : MonoBehaviour
{
    public class Archive
    {
        public MineMap Map;
        public int[] StatusArr;
        public int LeftMineCount;
        public float Time;
        public int LeftPullBackCount;
    }

    public static ArchiveMgr Instance;

    public void SaveArchive(
        EGameMode gameMode,
        MineMap mineMap,
        int[] statusArr,
        float time,
        int leftMineCount,
        int leftPullBackCount)
    {
        Archive archive = new Archive
        {
            Map = mineMap,
            StatusArr = statusArr,
            LeftMineCount = leftMineCount,
            Time = time,
            LeftPullBackCount = leftPullBackCount,
        };

        string str = JsonConvert.SerializeObject(archive);
        // Debug.Log(str);
        PlayerPrefs.SetString(gameMode.ToString(), str);
    }

    public Archive LoadArchive(EGameMode gameMode)
    {
        string archiveStr = PlayerPrefs.GetString(gameMode.ToString(), string.Empty);
        if (string.IsNullOrEmpty(archiveStr)) return null;
        Archive archive = JsonConvert.DeserializeObject<Archive>(archiveStr);
        // Debug.LogFormat("pullbackCount:{0}", archive.LeftPullBackCount);
        return archive;
    }

    public MineMap GetMineMap(EGameMode gameMode)
    {
        Archive archive = LoadArchive(gameMode);
        if (archive == null) return null;
        return archive.Map;
    }

    public void ClearArchive(EGameMode gameMode)
    {
        PlayerPrefs.DeleteKey(gameMode.ToString());
    }

    //=========================================公私分界线==================================================

    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
        Instance = this;
    }
}


